<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/23
 * Time: 13:37
 */

namespace Common\Model;


use Think\Model;

class DutyClassModel extends Model
{
    protected $_tableName = 'duty_class';
    protected $_auto = array(
        array('duty_type_id', 'generate_duty_id', self::MODEL_INSERT, 'function'),
        array('state', '1', self::MODEL_INSERT),
    );

    public function update($data){
        if (!isset($data['duty_type_code'])){
            return false;
        }
        $duty_type_code = $data['duty_type_code'];
        $where['duty_type_code'] = $duty_type_code;
        $record = $this->where($where)->find();
        if($record){
            $this->where($where)->save($data);
            return $record['duty_type_id'];
        }else{
            $data = $this->create($data);
            if($data){
                $id = $this->add();
                if(!$id){
                    return false;
                }else{
                    return $data['duty_type_id'];
                }
            }else{
                return false;
            }
//            if(empty($data['duty_type_id'])){

//            }else{
//                $id = $data['duty_type_id'];
//                $status = $this->save();
//                if(false === $status){
//                    return false;
//                }else{
//                    return $id;
//                }
//
//            }
        }
    }

}